<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('发运订单协助管理')"/>
<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <div class="layui-inline">
                        <label class="layui-form-label">订单号</label>
                        <div class="layui-input-inline" style="width: 200px;">
                            <input type="text" class="layui-input" id="khddh" name="khddh" placeholder="客户订单号"/>
                        </div>
                    </div>
                    <div class="layui-inline" style="width: 200px;">
                        <label class="layui-form-label">SO编号</label>
                        <input type="text" class="layui-input" id="fybh" name="fybh" placeholder="SO编号"/>
                    </div>
                    <div class="layui-inline" style="width: 200px;">
                        <label class="layui-form-label">波次编号</label>
                        <input type="text" class="layui-input" id="bcbh" name="bcbh" placeholder="波次编号"/>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">订单类型</label>
                        <div class="layui-input-inline" style="width: 200px;">
                            <select lay-ignore="lay-ignore" class="js-data-example-ajax" id="flSelect"
                                    name="fylx" select2 style="width: 200px"></select>
                        </div>
                    </div>
                    <div class="layui-inline inline-search-btn">
                        <a class="layui-btn layui-btn-normal search_btn" lay-event="searchEvent"
                           data-type="reload">查询</a>
                    </div>
                    <div class="layui-inline inline-reset-btn">
                        <button type="reset" class="layui-btn layui-btn-normal" id="chongzhi">重置
                        </button>
                    </div>
                    <div class="moreSearch" style="display: none">
                        <div class="layui-inline">
                            <label class="layui-form-label">wms创建时间</label>
                            <div class="layui-input-inline" style="width: 200px;">
                                <input type="text" class="layui-input" name="stime" id="stime"
                                       placeholder="wms创建时间"/>
                            </div>
                        </div>
                        <div class="layui-inline" style="width: 200px;">
                            <label class="layui-form-label">拣货状态</label>
                            <select name="jhzt" lay-filter="aihao3">
                                <option value="">全部</option>
                                <option value="0">初始</option>
                                <option value="1">部分拣货</option>
                                <option value="2">全部拣货</option>
                            </select>
                        </div>
                        <div class="layui-inline" style="width: 200px;">
                            <label class="layui-form-label">审核状态</label>
                            <select name="shzt" lay-filter="aihao1">
                                <option value="">全部</option>
                                <option value="0">未审核</option>
                                <option value="1">已审核</option>
                            </select>
                        </div>
                        <div class="layui-inline" style="width: 200px;">
                            <label class="layui-form-label">波次状态</label>
                            <select name="bczt" lay-filter="aihao2">
                                <option value="">全部</option>
                                <option value="0">未加入</option>
                                <option value="1">已加入</option>
                            </select>
                        </div>
                        <div class="layui-inline" style="width: 200px;">
                            <label class="layui-form-label">拆单状态</label>
                            <select name="cdzt" lay-filter="aihao5">
                                <option value="">全部</option>
                                <option value="0">未拆单</option>
                                <option value="1">已拆单</option>
                            </select>
                        </div>
                        <br/>
                        <div class="layui-inline" style="width: 200px;">
                            <label class="layui-form-label">装箱状态</label>
                            <select name="zxzt" lay-filter="aihao6">
                                <option value="">全部</option>
                                <option value="0">未装箱</option>
                                <option value="1">部分装箱</option>
                                <option value="2">全部装箱</option>
                            </select>
                        </div>
                        <div class="layui-inline" style="width: 200px;">
                            <label class="layui-form-label">交货方式</label>
                            <select name="jhfs" lay-filter="aihao7">
                                <option value="">全部</option>
                                <option value="0">发运</option>
                                <option value="1">自提</option>
                            </select>
                        </div>
                        <div class="layui-inline" style="width: 200px;">
                            <label class="layui-form-label">SO状态</label>
                            <select name="fyzt" lay-filter="aihao12">
                                <option value="">全部</option>
                                <option value="0">初始</option>
                                <option value="1">部分分配</option>
                                <option value="2">全部分配</option>
                                <option value="3">部分发运</option>
                                <option value="4">全部发运</option>
                                <option value="5">订单取消</option>
                                <option value="6">订单完成</option>
                            </select>
                        </div>
                    </div>
                </form>
                <div class="moreBtn"><i class="layui-icon layui-icon-triangle-d" style="color: #1E9FFF;"></i></div>
                <!--顶部按钮展示区域 【 tpl-button 】 -->
                <div class="group-button tpl-button" id="toolbar"></div>
                <!--列表-->
                <section class="panel panel-padding layui-card-body">
                    <div class="pro">
                        <table id="table" class="table text-nowrap"></table>
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>
<input hidden id="USER" th:value="${UserInfo}"/>
</body>
<style>
    .tooltip2 {
        display: inline-block;
        margin-left: 1rem;
    }
</style>
<div th:include="public/public_js::public_js"></div>
<div th:include="public/public_btn::public_btn"></div>

<script th:inline="javascript">
    const USER = JSON.parse($('#USER').val());
    $(function () {
        $(".moreBtn").on("click", function () {
            $(".moreSearch").toggle();
        });
    });


    var functions = [[${functions}]];
    layui.use(['list', 'layer', 'zzpUtils', 'jquery', 'laydate', 'tablebutton'], function () {
        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate,
            // 按钮引入
            tablebtn = layui.tablebutton;


        laydate.render({
            elem: '#stime'
            , theme: '#20a0ff'
            , range: '~'//练起来
        });
        //查询订单类型
        $('#flSelect').select2({
            ajax: {
                url: '/zxsdwms/wmsshipmentorder/getPoLx',
                dataType: 'json',
                type: 'POST',
                contentType: "application/json",
                data: function (params) {
                    var query = {
                        ddlx: params.term
                    };
                    return JSON.stringify(query);
                },
                processResults: function (data) {
                    var arr = new Array();
                    if (data) {
                        for (var i = 0; i < data.length; i++) {
                            arr.push({id: data[i].id, text: data[i].ddlx});
                        }
                    }
                    return {
                        results: arr
                    };
                },
                cache: true
            },
            language: "zh-CN",
            placeholder: '请选择订单类型',
            allowClear: true
        });

        //重置
        $("#chongzhi").on('click', function () {
            $('#flSelect').html('<option value="' + '' + '">' + '' + '</option>').trigger("change");
        })
        //初始化
        zzpUtils.webSocket.init();
        tablebtn.buildOnClick({
            type: 1,
            temp: $("#function_tpl"),
            functions: functions.headBtn,
            row: null,
            event: {
                //查询
                searchEvent: function () {
                    zzpUtils.refreshTable("#table");
                },
                // 查看明细
                getEvent: function (data) {
                    lookDialog(data.row);
                },
                //删除
                deleteEvent: function (data) {
                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id)
                        deleteClick(ids);
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            deleteClick(arr);
                        } else {
                            layer.msg("至少选择一条数据");
                        }
                    }
                },
                //审核
                auditEvent: function (data) {
                    var arr = [];
                    var $rows = $table.bootstrapTable('getSelections');
                    if ($rows.length > 0) {
                        arr = $.map($rows, function (row) {
                            return row.id;
                        })
                        audit(arr);
                    } else {
                        layer.msg("至少选择一条数据");
                    }
                },
                //附件管理
                accessoryEvent: function (data) {
                    accessoryDialog(data.row.id);
                },
                //查看库存余量
                searchinventoryEvent: function (data) {
                    searchinventoryDialog(data.row);
                },
                //复制订单
                copyOrderEvent: function (data) {
                    $.ajax({
                        url: '/zxsdwms/wmsshipmentorder/copyOrder',
                        type: 'POST',
                        dataType: 'json',
                        contentType: 'application/json',
                        data: JSON.stringify({id: data.row.id}),
                        success: function (data) {
                            if (data.type === 'success') {
                                layer.msg(data.message);
                            } else {
                                layer.msg(data.message);
                            }
                        },
                        error: function (err) {

                        }
                    })
                },
                //退单
                returninventoryEvent: function (data) {
                    tuidan(data.row.id);
                },
                //创建波次
                createNumberEvent: function (data) {
                    var arr = [];
                    var $rows = $table.bootstrapTable('getSelections');
                    if ($rows.length > 0) {
                        arr = $.map($rows, function (row) {
                            return row.id;
                        })
                        createNumber(arr);
                    } else {
                        layer.msg("至少选择一条数据");
                    }
                },
                //订单拆单
                orderSeparatedEvent: function (data) {
                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id)
                        orderSeparated(ids);
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            orderSeparated(arr);
                        } else {
                            layer.msg("至少选择一条数据");
                        }
                    }
                },
                //取消拆单
                cancelSeparatedEvent: function (data) {
                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id)
                        cancelSeparated(ids);
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            cancelSeparated(arr);
                        } else {
                            layer.msg("至少选择一条数据");
                        }
                    }
                },
                //分配
                allocationEvent: function (data) {
                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id)
                        allocation(ids);
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            allocation(arr);
                        } else {
                            layer.msg("至少选择一条数据");
                        }
                    }
                },
                //取消分配
                cancelAllocationEvent: function (data) {
                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id)
                        cancelAllocation(ids);
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            cancelAllocation(arr);
                        } else {
                            layer.msg("至少选择一条数据");
                        }
                    }
                },
                //拣货
                pickingEvent: function (data) {

                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id)
                        picking(ids);
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            picking(arr);
                        } else {
                            layer.msg("至少选择一条数据");
                        }
                    }
                },
                //抵扣审核
                deductionAuditEvent: function (data) {
                    var arr = [];
                    var $rows = $table.bootstrapTable('getSelections');
                    if ($rows.length > 0) {
                        arr = $.map($rows, function (row) {
                            return row.id;
                        })
                        deductionAudit(arr);
                    } else {
                        layer.msg("至少选择一条数据");
                    }
                },
                //装箱
                packingEvent: function (data) {

                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id)
                        packing(ids);
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            packing(arr);
                        } else {
                            layer.msg("至少选择一条数据");
                        }
                    }
                },
                //取消装箱
                cancelPackingEvent: function (data) {
                    var arr = [];
                    var $rows = $table.bootstrapTable('getSelections');
                    if ($rows.length > 0) {
                        arr = $.map($rows, function (row) {
                            return row.id;
                        })
                        cancelPacking(arr);
                    } else {
                        layer.msg("至少选择一条数据");
                    }
                },
                //查看拆单明细
                searchSeparatedDetailEvent: function (data) {
                    if (data.row) {
                        searchSeparatedDetailDialog(data.row);
                    }
                },
                //查看分配明细
                searchAllocationDetailEvent: function (data) {
                    if (data.row) {
                        searchAllocationDetailDialog(data.row);
                    }
                },
                //查看装箱明细
                searchPackingDetailEvent: function (data) {
                    if (data.row) {
                        searchPackingDetailDialog(data.row);
                    }
                },
                //标记
                signEvent: function (data) {
                    var arr = [];
                    var $rows = $table.bootstrapTable('getSelections');
                    if ($rows.length > 0) {
                        arr = $.map($rows, function (row) {
                            return row.id;
                        })
                        sign(arr);
                    } else {
                        layer.msg("至少选择一条数据");
                    }
                },
                //打印
                printBoxLabelEvent: function (data) {
                    if (data.row) {
                        printBoxLabel(data.row);
                    }
                }

            }
        });

        //退单
        var idex;
        function tuidan(id) {
            layer.open({
                title: '查看关联退单',
                type: 2,
                content: "/zxsdwms/outOrder/selectTuiDan",
                area: ['90%', '65%'],
                btn: ['保存', '取消'],
                btn1: function (index, layero) {
                    idex = index;
                    zzpUtils.confirm("您将对选择的发运订单进行退单", function (index) {
                        $.ajax({
                            url: '/zxsdwms/wmsSplit/setTdzt',
                            type: 'POST',
                            dataType: 'json',
                            contentType: 'application/json',
                            data: JSON.stringify({id: id}),
                            success: function (data) {
                                setTimeout(function () {
                                    layer.close(idex); //再执行关闭
                                    if (data.type == 'success') {
                                        layer.msg(data.title);
                                    } else {
                                        layer.msg(data.message);
                                    }
                                }, 500);
                            },
                            error: function (err) {
                            }
                        })
                    })
                },
                btn2: function (index, layero) {
                    layer.close(index);
                }
            })
        }
        //查看
        function lookDialog(row) {
            zzpUtils.dialog({
                title: "查看明细",
                type: 2,
                content: "/outOrder/LookDetail?id=" + row.id,
                area: ['80%', '80%']
            });
        }

        //删除
        function deleteClick(ids) {
            var Ids = {ids: ids};
            zzpUtils.confirm("您将作废发运订单", function (index) {
                $.ajax({
                    url: '/zxsdwms/wmsshipmentorder/updateSfyx',
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(Ids),
                    success: function (data) {
                        if (data.type === 'success') {
                            layer.msg(data.title);
                            $('#table').bootstrapTable('refresh');
                        } else {
                            layer.msg(data.message);
                        }
                    }
                })
            })
        }

        //审核
        function audit(data) {
            var ids = {ids: data};
            zzpUtils.confirm("您将审核选择的发运订单", function (index) {
                $.ajax({
                    url: '/zxsdwms/wmsshipmentorder/updateShzt',
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(ids),
                    success: function (data) {
                        if (data.type === 'success') {
                            layer.msg(data.title);
                            $('#table').bootstrapTable('refresh');
                        } else {
                            layer.msg(data.message);
                        }
                    },
                    error: function (err) {
                        console.log(err);
                    }
                })
            })
        }

        //附件管理
        function accessoryDialog(id) {
            zzpUtils.dialog({
                title: " 附件管理",
                type: 2,
                content: "/outOrder/getFuJian?id="+id,
                area: ['80%', '70%'],
                end: function () {
                    console.log('dialog关闭回调');
                    $('#table').bootstrapTable('refresh');
                }
            });
        }

        //查看库存余量
        function searchinventoryDialog(row) {
            localStorage.id = row.id;
            zzpUtils.dialog({
                title: "查看库存余量",
                type: 2,
                content: "/outOrder/SearchInventory",
                area: ['80%', '70%']
            })
        }


        //创建波次
        function createNumber(data) {
            var Ids = {ids: data};
            zzpUtils.confirm("您将对选择的发运订单进行创建波次", function (index) {
                $.ajax({
                    url: '/zxsdwms/wmswave/add',
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(Ids),
                    success: function (data) {
                        if (data.type === 'success') {
                            layer.msg(data.title);
                            $('#table').bootstrapTable('refresh');
                        } else {
                            layer.msg(data.message);
                        }
                    }
                })
            })
        }

        //订单拆单
        function orderSeparated(data) {
            var Ids = {ids: data};
            zzpUtils.confirm("您将对选择的发运订单进行订单拆单", function (index) {
                $.ajax({
                    url: '/zxsdwms/wmsSplit/split',
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(Ids),
                    success: function (data) {
                        if (data.type === 'success') {
                            layer.msg(data.title);
                            $('#table').bootstrapTable('refresh');
                        } else {
                            layer.msg(data.message);
                        }
                    }
                })
            })
        }

        //取消拆单
        function cancelSeparated(data) {
            var Ids = {ids: data};
            zzpUtils.confirm("您将对选择的发运订单进行取消拆单", function (index) {
                $.ajax({
                    url: '/zxsdwms/wmsSplit/cancel',
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(Ids),
                    success: function (data) {
                        if (data.type === 'success') {
                            layer.msg(data.title);
                            $('#table').bootstrapTable('refresh');
                        } else {
                            layer.msg(data.message);
                        }
                    }
                })
            })
        }

        //分配
        function allocation(data) {
            var Ids = {ids: data};
            zzpUtils.confirm("您将对选择的发运订单进行分配", function (index) {
                $.ajax({
                    url: '/zxsdwms/wmsdistribution/distribution',
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(Ids),
                    success: function (data) {
                        if (data.type === 'success') {
                            layer.msg(data.title);
                            $('#table').bootstrapTable('refresh');
                        } else {
                            layer.msg(data.message);
                        }
                    }
                })
            })
        }

        //取消分配
        function cancelAllocation(data) {
            var Ids = {ids: data};
            zzpUtils.confirm("您将对选择的发运订单进行取消分配", function (index) {
                $.ajax({
                    url: '/zxsdwms/wmsdistribution/cancelDistribution',
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(Ids),
                    success: function (data) {
                        if (data.type === 'success') {
                            layer.msg(data.title);
                            $('#table').bootstrapTable('refresh');
                        } else {
                            layer.msg(data.message);
                        }
                    }
                })
            })
        }

        //拣货
        function picking(data) {
            var Ids = {ids: data};
            zzpUtils.confirm("您将对选择的发运订单进行拣货", function (index) {
                $.ajax({
                    url: '/zxsdwms/wmspicking/pick',
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(Ids),
                    success: function (data) {
                        if (data.type === 'success') {
                            layer.msg(data.title);
                            $('#table').bootstrapTable('refresh');
                        } else {
                            layer.msg(data.message);
                        }
                    }
                })
            })
        }

        //抵扣审核
        function deductionAudit(data) {
            var Ids = {ids: data};
            zzpUtils.confirm("您将对选择的发运订单进行抵扣审核的操作", function (index) {
                $.ajax({
                    url: '/zxsdwms/wmsloading/deductible',
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(Ids),
                    success: function (data) {
                        if (data.type === 'success') {
                            layer.msg(data.title);
                            $('#table').bootstrapTable('refresh');
                        } else {
                            layer.msg(data.message);
                        }
                    }
                })
            })
        }


        //装箱
        function packing(data) {
            var Ids = {ids: data};
            zzpUtils.confirm("您将对选择的发运订单进行装箱的操作", function (index) {
                $.ajax({
                    url: '/zxsdwms/wmsbox/boxZx',
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(Ids),
                    success: function (data) {
                        if (data.type === 'success') {
                            layer.msg(data.title);
                            $('#table').bootstrapTable('refresh');
                        } else {
                            layer.msg(data.message);
                        }
                    }
                })
            })
        }

        //取消装箱
        function cancelPacking(data) {
            var Ids = {ids: data};
            zzpUtils.confirm("您将对选择的发运订单进行取消装箱的操作", function (index) {
                $.ajax({
                    url: '/zxsdwms/wmsbox/cancelBoxZx',
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(Ids),
                    success: function (data) {
                        if (data.type === 'success') {
                            layer.msg(data.title);
                            $('#table').bootstrapTable('refresh');
                        } else {
                            layer.msg(data.message);
                        }
                    }
                })
            })
        }

        //查看拆单明细
        function searchSeparatedDetailDialog(row) {
            localStorage.id = row.id;
            zzpUtils.dialog({
                title: "查看拆单明细",
                type: 2,
                content: "/outOrder/SeparatedDetail",
                area: ['80%', '80%']
            })
        }
        //查看分配明细
        function searchAllocationDetailDialog(row) {
            localStorage.id = row.id;
            zzpUtils.dialog({
                title: "查看分配明细",
                type: 2,
                content: "/outOrder/AllocationDetail",
                area: ['80%', '80%']
            })
        }
        //查看装箱明细
        function searchPackingDetailDialog(row) {
            localStorage.id = row.id;
            zzpUtils.dialog({
                title: "查看装箱明细",
                type: 2,
                content: "/outOrder/PackingDetail",
                area: ['80%', '80%']
            })
        }

        //标记
        function sign(data) {
            var ids = {ids: data};
            zzpUtils.confirm("您将标记选择的发运订单", function (index) {
                $.ajax({
                    url: '/zxsdwms/wmsshipmentorder/updateZt',
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(ids),
                    success: function (data) {
                        layer.msg(data.message);
                        if (data.type === 'success') {
                            $('#table').bootstrapTable('refresh');
                        }
                    },
                    error: function (err) {
                        console.log(err);
                    }
                })
            })
        }

        //打印
        function printBoxLabel(row) {
            var ids = [];
            ids.push(row.id);
            var data;
            $.ajax({
                url: '/zxsdwms/wmsbox/printeZxmx',
                type: 'POST',
                dataType: 'json',
                contentType: 'application/json',
                data: JSON.stringify({ids: ids}),
                success: function (DATA) {console.log(DATA);
                        data = DATA.rows;
                         var  LODOP = getLodop();
                        LODOP.PRINT_INIT('打印箱标签信息');
                         var index = 0;
                         var leftwidth = 10;
                         for (var s=0;s<data.length;s++) {
                            LODOP.NewPage();
                            // LODOP.ADD_PRINT_RECT(5, 15, 360, 275, 0, 1); // 画边框
                            LODOP.ADD_PRINT_TEXT(2, 93 + leftwidth, 250, 25, data[index].show_rent);
                            LODOP.SET_PRINT_STYLEA(0, 'FontName', '隶书');
                            LODOP.SET_PRINT_STYLEA(0, 'FontSize', 13);
                            LODOP.SET_PRINT_STYLEA(0, 'Bold', 1);
                            LODOP.ADD_PRINT_TEXT(31, 3 + leftwidth, 57, 20, '起始站：');
                            LODOP.ADD_PRINT_TEXT(31, 63 + leftwidth, 145, 20, data[index].ownermc);
                            LODOP.ADD_PRINT_TEXT(31, 210 + leftwidth, 57, 20, '收货人：');
                            LODOP.ADD_PRINT_TEXT(31, 276 + leftwidth, 100, 20, data[index].lxrxm);
                            LODOP.ADD_PRINT_TEXT(53, 3 + leftwidth, 57, 20, '订单号：');
                            LODOP.ADD_PRINT_TEXT(53, 63 + leftwidth, 145, 20, data[index].sobh);
                            LODOP.ADD_PRINT_TEXT(53, 210 + leftwidth, 69, 20, '联系电话：');
                            LODOP.ADD_PRINT_TEXT(53, 276 + leftwidth, 81, 20, data[index].lxrdh);
                            LODOP.ADD_PRINT_TEXT(76, 3 + leftwidth, 69, 20, '收货地址：');
                            LODOP.ADD_PRINT_TEXT(76, 67 + leftwidth, 291, 37, data[index].khdz);
                            LODOP.ADD_PRINT_TEXT(123, 3 + leftwidth, 124, 20, '散箱数量：' + data[index].sxsl);
                            LODOP.ADD_PRINT_TEXT(123, 118 + leftwidth, 104, 20, '整箱数量：' + data[index].zxsl);
                            LODOP.ADD_PRINT_TEXT(123, 220 + leftwidth, 138, 20, '当前：' + data[index].xxh + '/' + data[index].maxXxh + ' ' + data[index].zslx);
                            LODOP.ADD_PRINT_RECT(0, 0 + leftwidth, '100mm', '80mm', 0, 1); // 外边框
                            // LODOP.ADD_PRINT_RECT(136, 0 + leftwidth, '100mm', 111, 0, 1); // 明细边框
                            LODOP.ADD_PRINT_LINE(136, 10, 136, '102mm', 0, 1); // 横线
                            LODOP.ADD_PRINT_TEXT(138, 2 + leftwidth, 36, 20, '序号');
                            LODOP.ADD_PRINT_TEXT(138, 45 + leftwidth, 167, 20, '货品名称');
                            LODOP.ADD_PRINT_TEXT(138, 210 + leftwidth, 34, 20, '规格');
                            LODOP.ADD_PRINT_TEXT(138, 295 + leftwidth, 36, 20, '单位');
                            LODOP.ADD_PRINT_TEXT(138, 339 + leftwidth, 35, 20, '数量');
                            if (data[index].boxMx.length > 0) {
                                var height;
                                for (var mx = 0, mcx = 0; mx < data[index].boxMx.length; mx++, mcx++) {
                                    var datalength = data[index].boxMx.length;
                                    console.log('datalength', datalength);
                                    console.log('mmmmx', mx);
                                    var mcxs;
                                    if (mx < 7) {
                                        height = 158;
                                        mcxs = mcx;
                                    } else if (mx < 22) {
                                        height = 10;
                                        mcxs = mcx - 7;
                                    } else {
                                        height = 10;
                                        mcxs = mcx - 22;
                                    }
                                    LODOP.ADD_PRINT_TEXT(height + mcxs * 20, 1 + leftwidth, 37, 20, mx + 1);
                                    LODOP.ADD_PRINT_TEXT(height + mcxs * 20, 45 + leftwidth, 167, 20, data[index].boxMx[mx].goodsMc);
                                    LODOP.ADD_PRINT_TEXT(height + mcxs * 20, 200 + leftwidth, 122, 20, data[index].boxMx[mx].gg || ''); // 规格
                                    LODOP.ADD_PRINT_TEXT(height + mcxs * 20, 296 + leftwidth, 34, 20, data[index].boxMx[mx].dw || ''); // 单位
                                    LODOP.ADD_PRINT_TEXT(height + mcxs * 20, 339 + leftwidth, 48, 20, data[index].boxMx[mx].sl);
                                    if (datalength < 5) {
                                        LODOP.ADD_PRINT_LINE(246, 10, 246, '102mm', 0, 1);
                                    } else if (datalength >= 5 && datalength < 7) {
                                        if (mx === (datalength - 1)) {
                                            console.log('分页');
                                            LODOP.NewPage();
                                            LODOP.ADD_PRINT_RECT(0, 0 + leftwidth, '100mm', '80mm', 0, 1);
                                            LODOP.ADD_PRINT_LINE(246, 10, 246, '102mm', 0, 1);
                                        }
                                    } else if (datalength >= 7 && datalength < 19) {
                                        if (mx === 6) {
                                            console.log('分页');
                                            LODOP.NewPage();
                                            LODOP.ADD_PRINT_RECT(0, 0 + leftwidth, '100mm', '80mm', 0, 1);
                                            LODOP.ADD_PRINT_LINE(246, 10, 246, '102mm', 0, 1);
                                        }
                                    } else if (datalength >= 19 && datalength < 22) {
                                        if (mx === 6 || mx === (datalength - 1)) {
                                            console.log('分页');
                                            LODOP.NewPage();
                                            LODOP.ADD_PRINT_RECT(0, 0 + leftwidth, '100mm', '80mm', 0, 1);
                                            if (mx === (datalength - 1)) {
                                                LODOP.ADD_PRINT_LINE(246, 10, 246, '102mm', 0, 1);
                                            }
                                        }
                                    } else if (datalength >= 22) {
                                        if (mx === 6 || mx === 21) {
                                            console.log('分页');
                                            LODOP.NewPage();
                                            LODOP.ADD_PRINT_RECT(0, 0 + leftwidth, '100mm', '80mm', 0, 1);
                                            if (mx === 21) {
                                                LODOP.ADD_PRINT_LINE(246, 10, 246, '102mm', 0, 1);
                                            }
                                        }
                                    }
                                }
                            }
                            LODOP.ADD_PRINT_LINE(247, 95 + leftwidth, 302, 95 + leftwidth, 0, 1); // 画竖线
                            LODOP.ADD_PRINT_TEXT(257, 1 + leftwidth, 98, 37, data[index].xx); // 箱型
                            LODOP.ADD_PRINT_TEXT(267, 1 + leftwidth, 110, 40, data[index].llzl); // 理论重量
                            LODOP.ADD_PRINT_BARCODE(250, 103 + leftwidth, 251, 49, 'Code39', data[index].xbh);
                            index++;
                        }
                        LODOP.PREVIEW();
                }
            })
        }


        laydate.render({
            elem: '#createTime'
            , range: true
        });
        // 主页面table
        var $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            pagination: true,
            isOperate: true,
            //functions: functions.tableBtn,
            url: '/wmsshipmentorder/listByBcAndWjh',
            columns: [
                {field: '', checkbox: true},
                {field: 'fybh', title: 'SO编号'},
                {field: 'khddh', title: '客户订单号'},
                {field: 'show_fylx', title: 'SO类型'},
                {field: 'khbh', title: '客户编号'},
                {field: 'khmc', title: '客户名称'},
                {field: 'lxrxm', title: '联系人'},
                {field: 'show_dpczt', title: '批次状态'},
                {field: 'xlmc', title: '路线'},
                {field: 'bcbh', title: '波次编号', visible: false},
                {field: 'yxj', title: '优先级', visible: false},
                {field: 'khdz', 'title': '客户地址', visible: false},
                {field: 'show_shzt', title: '审核状态', visible: false},
                {field: 'show_cdzt', title: '拆单状态', visible: false},
                {field: 'zyf', title: '总运费', visible: false},
                {field: 'show_jhfs', title: '交货方式', visible: false},
                {field: 'show_zxzt', title: '装箱状态', visible: false},
                {field: 'show_bczt', title: '波次状态', visible: false},
                {field: 'show_jhzt', title: '拣货状态', visible: false},
                {field: 'show_jhrwzt', title: '拣货任务状态', visible: false},
                {field: 'show_fyzt', title: 'SO状态', visible: false},
                {field: 'jhfhsj', title: '计划发货时间', visible: false},
                {field: 'yqjhsj', title: '要求交货时间', visible: false},
                {field: 'cjsj', title: 'wms创建时间', visible: false},
                {field: 'show_tdzt', title: '退单状态', visible: false},
                {field: 'show_thzt', title: '退货状态', visible: false}
            ],
            queryParams: function () {//查询条件
                return zzpUtils.getFormJson($("#searchForm"));
            },
            operateFormatter: operateFormatter

        });

        /*表格右侧按钮*/
        function operateFormatter(value, row, index) {
            var btn = '', button = '', buttons1 = '', buttons2 = '';
            var buttons = '<a class="tooltip2" id="tooltip' + row.id + '" data-tooltip-content="#tool' + row.id + '">更多</a>'
                + '<div class="tooltip_templates"><span id="tool' + row.id + '">';
            for (var i = 0; i < functions.tableBtn.length; i++) {
                var item = functions.tableBtn[i];
                var Disable = '<button class="layui-btn layui-btn-xs layui-btn-disabled" disabled lay-event="' + item.event + '">' + item.name + '</button>';
                var Enable = '<button class="layui-btn layui-btn-xs layui-btn-normal" lay-event="' + item.event + '">' + item.name + '</button>';

                //更多之外
                if (item.event === 'getEvent' ||  item.event === 'deleteEvent' || item.event === 'allocationEvent' || item.event === 'pickingEvent' || item.event === 'packingEvent' || item.event === 'printBoxLabelEvent') {
                    switch (item.event) {
                        case 'getEvent':
                            buttons1 += '<button class="layui-btn layui-btn-xs layui-btn-normal" lay-event="' + item.event + '">' + item.name + '</button>';
                            break;
                        case 'allocationEvent'://分配
                            if(USER.auth.indexOf('outOperation_shipment_allot')!==-1 && row.cdzt==='1'&& row.fyzt ==='0' && row.jhrwzt ==='0')
                                buttons1 += Enable;
                            else
                                buttons1 += Disable;

                            break;
                        case 'deleteEvent'://删除
                            if(USER.auth.indexOf('outOperation_shipment_disable')!==-1 && row.fyzt ==='0' && row.shzt === '0')
                                buttons1 += Enable;
                            else
                                buttons1 += Disable;

                            break;
                        case 'packingEvent':// 装箱
                            if(USER.auth.indexOf('outOperation_shipment_packing')!==-1 && (row.fyzt ==='1' || row.fyzt ==='2') && (row.zxzt ==='0' || row.zxzt ==='2') &&  (row.cdzt==='1') && row.jhrwzt ==='0')
                                buttons1 += Enable;
                            else
                                buttons1 += Disable;
                            break;
                        case 'pickingEvent'://拣货
                            if(USER.auth.indexOf('outOperation_shipment_picking')!==-1 && (row.fyzt==='1'|| row.fyzt==='2') && row.jhrwzt !=='2' && row.jhzt ==='0')
                                buttons1 += Enable;
                            else
                                buttons1 += Disable;

                            break;
                        case 'printBoxLabelEvent'://打印
                            if(row.zxzt!=='0')
                                buttons1 += Enable;
                            else
                                buttons1 += Disable;

                            break;
                        default:
                            buttons1 += Enable;
                    }
                } else {
                    //更多之内
                    switch (item.event) {
                        case 'deductionAuditEvent':// 抵扣审核
                            if (row.show_fylx === '抵扣')
                                buttons2 += Enable;
                            else
                                buttons2 += Disable;
                            break;
                        case 'borrowCargoEvent': // 借货完结
                            if (row.show_fylx ==='借货' && row.jhwjzt==='0')
                                buttons2 += Enable;
                            else
                                buttons2 += Disable;
                            break;
                        case 'returninventoryEvent': // 退单
                            if ((row.fyzt ==='3' || row.fyzt==='4' || row.fyzt ==='0') && (row.thzt === '0') && (row.tdzt!=='2'))
                                buttons2 += Enable;
                            else
                                buttons2 += Disable;
                            break;
                        case 'returninventoryEvent': // 标记
                            if (USER.auth.indexOf('outOperation_shipment_sign')!==-1 &&row.fyzt === '3')
                                buttons2 += Enable;
                            else
                                buttons2 += Disable;
                            break;
                        case 'createNumberEvent': // 创建波次
                            if (USER.auth.indexOf('outOperation_shipment_create')!==-1 && row.bczt ==='0'&& row.fyzt ==='0')
                                buttons2 += Enable;
                            else
                                buttons2 += Disable;
                            break;
                        case 'orderSeparatedEvent': // 订单拆单
                            if (USER.auth.indexOf('outOperation_shipment_remove')!==-1 &&  row.shzt ==='1' && row.cdzt === '0')
                                buttons2 += Enable;
                            else
                                buttons2 += Disable;
                            break;
                        case 'cancelSeparatedEvent': // 取消拆单
                            if (USER.auth.indexOf('outOperation_shipment_cancel')!==-1 && row.cdzt==='1' && row.fyzt ==='0')
                                buttons2 += Enable;
                            else
                                buttons2 += Disable;
                            break;
                        case 'cancelAllocationEvent': // 取消分配
                            if (USER.auth.indexOf('business_customerFile_search')!==-1 && (row.jhzt ==='0'&& row.zxzt==='0' && row.fyzt !=='0' && row.jhrwzt ==='0'))
                                buttons2 += Enable;
                            else
                                buttons2 += Disable;
                            break;
                        case 'cancelPackingEvent': // 取消装箱
                            if (USER.auth.indexOf('business_customerFile_search')!==-1 && (row.zxzt ==='1' || row.zxzt === '2') && row.jhrwzt ==='0')
                                buttons2 += Enable;
                            else
                                buttons2 += Disable;
                            break;
                        case 'searchSeparatedDetailEvent': // 查看拆单明细
                            if (USER.auth.indexOf('outOperation_shipment_splitsingledetailed')!==-1)
                                buttons2 += Enable;
                            else
                                buttons2 += Disable;
                            break;
                        case 'searchAllocationDetailEvent': // 查看分配明细
                            if (USER.auth.indexOf('outOperation_shipment_allotdetailed')!==-1)
                                buttons2 += Enable;
                            else
                                buttons2 += Disable;
                            break;
                        default:
                            buttons2 += Enable;
                    }
                }
            }
            button += buttons1;
            button += buttons;
            button += buttons2;
            button += '</span></div>';
            return button;
        }



    });
</script>

</html>